package client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class Client1 {

    // private

    public static void client() {
        try {
            Socket client = new Socket("127.0.0.1", 8888);

            BufferedWriter os = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

            BufferedReader br = new BufferedReader(new FileReader(new File("D:/autolog.txt")));
            String line = null;
            String backLine = null;
            while ((line = br.readLine()) != null) {
                if ("\n".equals(line) || null == line || "".equals(line)) {
                    break;
                }
                os.write(line + "\n"); // 一定要加\n如果不加会一直阻塞等待
                os.flush();
                backLine = in.readLine();
                System.out.println("Client Print: " + backLine + " :From Server!");
//                Thread.sleep(1 * 1000);
            }
            in.close();
            br.close();
            os.close();
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        } /*catch (InterruptedException e) {
            e.printStackTrace();
        }*/

    }

    public static void main(String[] args) {
        client();
    }

}
